package com.uplooking.controller;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import com.alibaba.fastjson.JSONObject;
import com.uplooking.service.BusService;

@Controller
public class BusController {

	@Autowired
	private BusService busService;

	@RequestMapping(value = "/bus/index", method = RequestMethod.GET)
	public String methodMenu6() {
		return "resource/bus";
	}

	@ResponseBody
	@RequiresPermissions("bus!list")
	@RequestMapping(value = "/bus/list", method = RequestMethod.GET, produces = { "application/json;charset=utf-8" })
	public String methodBus1(String bsno, int index, int size, int step) throws Exception {
		String text = JSONObject.toJSONString(busService.getBusList(bsno, index, size, step));
		System.out.println(text);
		return text;
	}

	@ResponseBody
	@RequiresPermissions("bus!add")
	@RequestMapping(value = "/bus/add", method = RequestMethod.POST, produces = { "application/json;charset=utf-8" })
	public String methodBus2(String bsno, String bstype, String bscolor, int bsprice, int bsrent, int bsdeposit,
			String bsdesc, MultipartFile myfile) throws Exception {
		String text = JSONObject.toJSONString(
				busService.addBus("CP" + bsno, bstype, bscolor, bsprice, bsrent, bsdeposit, bsdesc, myfile));
		System.out.println(text);
		return text;
	}

	@ResponseBody
	@RequiresPermissions("bus!update")
	@RequestMapping(value = "/bus/update", method = RequestMethod.POST, produces = { "application/json;charset=utf-8" })
	public String methodBus3(String bsno, String bstype, String bscolor, int bsprice, int bsrent, int bsdeposit,
			String bsdesc, MultipartFile myfile) throws Exception {
		String text = JSONObject
				.toJSONString(busService.updateBus(bsno, bstype, bscolor, bsprice, bsrent, bsdeposit, bsdesc, myfile));
		System.out.println(text);
		return text;
	}

	@ResponseBody
	@RequiresPermissions("bus!stop")
	@RequestMapping(value = "/bus/stop", method = RequestMethod.GET, produces = { "application/json;charset=utf-8" })
	public String methodBus4(String bsno) throws Exception {
		String text = JSONObject.toJSONString(busService.stopBus(bsno));
		System.out.println(text);
		return text;
	}

	@ResponseBody
	@RequiresPermissions("bus!stop")
	@RequestMapping(value = "/bus/unstop", method = RequestMethod.GET, produces = { "application/json;charset=utf-8" })
	public String methodBus5(String bsno) throws Exception {
		String text = JSONObject.toJSONString(busService.unStopBus(bsno));
		System.out.println(text);
		return text;
	}

}
